const xlsx = require("xlsx");
const fs = require("fs");

const axios = require("axios");

const reacExcel = () => {
  // 读取Excel文件
  const workbook = xlsx.readFile("创业板业绩.xlsx");

  // 获取第一个工作表
  const sheetName = workbook.SheetNames[0];
  const worksheet = workbook.Sheets[sheetName];

  // 解析工作表为JSON
  const jsonData = xlsx.utils.sheet_to_json(worksheet);

  // 提取第一列数据
  const firstColumnData = jsonData.map(
    (row) => `${row[Object.keys(row)[0]]}.SZ`
  );

  return firstColumnData;
};
const array = reacExcel();

const obj = {
  cyb: {
    name: "创业板股池",
    groupId: "1053008",
  },
  zx: {
    name: "自选",
    groupId: "720713",
  },
};

const add = (groupId) => {
  const url = "https://stock.cheesefortune.com/api/v2/opt/addOpt";
  const urlParams = array.map(
    (item) =>
      new URLSearchParams({
        code: item,
        groupIds: groupId,
      })
  );

  const headers = {
    token:
      "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1MjM2QSIsInN1YiI6IlhWb0RhZk1DRmFvNDhZTng2b2Vib2J2U1hZKzJkd2lJN2tjMDFGRlRTTkt1L25zTGpDNnEvQUo1UkxEN3pLSm96QjFrTUxHUDMzOEhLeFJhU0RmZ0xUaWY1VXlrRFNvd2RGTGNHek95Q3NCZVZKZE1qc3NkVUMxcUpQT1hqaUYrIiwiaWF0IjoxNzM2NjUzNDY3LCJleHAiOjIwNTIwMTM0Njd9.QHVYwNx0pX5s9RGtf6vWLAnicAtpXCoDWWAblencUwY",
  };

  urlParams.slice(20, 30).forEach((params) => {
    console.log("urlParams.slice ~ params:", params);
    axios
      .get(url, { params, headers })
      .then((response) => console.log(response.data))
      .catch((error) => console.log(error));
  });
};

add(obj.cyb.groupId);
